package client;

import java.io.*;
import java.net.Socket;

public class TimeClient {
	public static void main(String[] args) {
		Socket s = null;
		BufferedReader in = null;//读取文本信息的流,可逐行读取
		PrintWriter out = null;		//向文本输出流打印对象的格式化表示形式,此类实现在 PrintStream 中的所有 print 方法.可以逐行写出.这个输出流只能用于文本
												//InputStreamReader.桥梁流,将字节转换成字符.
												//OutputSteamWriter.桥梁流,将字符转换成字节.
		try {
			s = new Socket("172.17.4.74", 9999);
			System.out.println("连接OK");
			System.out.println(System.currentTimeMillis() % 10000);
		in = new BufferedReader(new InputStreamReader(s.getInputStream()));
			out = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
			while (true) {
				out.println("ask");		//发送给Service
				out.flush();					//刷新缓存中的
				Thread.sleep(2000);
				System.out.println("time :" + in.readLine());
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
				s.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}